package com.apes.fico.finance.respository;

import com.apes.fico.finance.model.gl.CarryOverPL;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface CarryOverPLRepository extends CustomRepository<CarryOverPL, String> {
    @Query(value = "SELECT COUNT(A.ID) FROM OUTBOX_EVENT A WHERE A.OUTBOX_SUBSCRIBER_ID IN ('local:CarryOver.syncMonthlyChart','local:CarryOver.syncMonthlyChartByType') " +
            "AND (SUBSTR(A.AGGREGATE_ID,INSTR(A.AGGREGATE_ID,'&', -1, 1) + 1) IN (SELECT T.ID FROM GL_CHART T WHERE T.COMPANY_ID = :companyId AND T.PERIOD = :period) " +
            "OR SUBSTR(A.AGGREGATE_ID,INSTR(A.AGGREGATE_ID,'&', -1, 1) + 1) IN (SELECT T.ID FROM GL_CHART_AUX T WHERE T.COMPANY_ID = :companyId AND T.PERIOD = :period))",nativeQuery = true)
    int findOutboxEvent(@Param("companyId") String companyId, @Param("period") int period);
}
